<script setup lang="ts">
// 获取天气请求的函数
import { getWeather } from '../../request/air'
import { ref } from 'vue'
import IndexTitle from './IndexTitle.vue'
// 定义接口
interface typeWeather {
    [key: string]: any
}
// 定义天气数据
const weather = ref<typeWeather>({})
// 定义今天天气情况图片路径
const todayImg = ref('')
// 定义明天天气情况数据
const tomorrowWea = ref<typeWeather>({})
// 定义明天天气情况图片路径
const tomorrowImg = ref('')
// 获取当天天气数据
getWeather('v63').then(resp => {
    console.log('当天天气数据', resp)
    weather.value = resp.data
    // 天气状况
    switch (resp.data.wea_img) {
        case 'yu':
            todayImg.value = '/src/assets/yu.png'
            break
        case 'xue':
            todayImg.value = '/src/assets/xue.png'
            break
        case 'yin':
            todayImg.value = '/src/assets/yin.png'
            break
        case 'qing':
            todayImg.value = '/src/assets/qing.png'
            break
        case 'yun':
            todayImg.value = '/src/assets/duoyun.png'
            break
    }
})

// 获取明天天气情况
getWeather('v9').then(resp => {
    console.log('明天天气', resp)
    tomorrowWea.value = resp.data.data[1]
    switch (resp.data.data[1].wea_img) {
        case 'yu':
            tomorrowImg.value = '/src/assets/yu.png'
            break
        case 'xue':
            tomorrowImg.value = '/src/assets/xue.png'
            break
        case 'yin':
            tomorrowImg.value = '/src/assets/yin.png'
            break
        case 'qing':
            tomorrowImg.value = '/src/assets/qing.png'
            break
        case 'yun':
            tomorrowImg.value = '/src/assets/duoyun.png'
            break
    }
})
</script>

<template>
    <div class="box">
        <!-- 标题 -->
        <Index-Title title="环境监测"></Index-Title>
        <!-- 内容 -->
        <div class="content">
            <!-- 顶部今天的气温 -->
            <div class="top">
                <!-- 左边的体感温度 -->
                <div class="left">{{ weather.tem }}°C</div>
                <!-- 中间的最低温和最高温 -->
                <div class="center">
                    <!-- 空气质量 -->
                    <div class="air">{{ weather.air }}{{ weather.air_level }}</div>
                    <!-- 最低温和最高温 -->
                    <div class="tem">{{ weather.tem2 }}°C~{{ weather.tem1 }}°C</div>
                </div>
                <!-- 右边的天气情况 -->
                <div class="right">{{ weather.air_tips ? weather.air_tips.slice(0, 4) : '' }} </div>
            </div>
            <!-- 体感、风力、湿度 -->
            <div class="tfs">
                <!-- 体感 -->
                <div>
                    <img src="../../assets/tiganwendu.png" alt="">
                    <span>体感</span>
                    <span>{{ weather.tem }}°C</span>
                </div>
                <!-- 风力 -->
                <div>
                    <img src="../../assets/fengli.png" alt="">
                    <span>风力</span>
                    <span>{{ weather.win_speed }}</span>
                </div>
                <!-- 湿度 -->
                <div>
                    <img src="../../assets/shidu.png" alt="">
                    <span>湿度</span>
                    <span>{{ weather.humidity }}</span>
                </div>
            </div>
            <!-- 今天和明天 -->
            <div class="tm">
                <!-- 今天 -->
                <div class="today">
                    <!-- 上面的温度 -->
                    <div class="temp">
                        <span>{{ weather.tem2 }}~{{ weather.tem1 }}°C</span>
                        <img :src="todayImg" alt="">
                    </div>
                    <!-- 空气质量 -->
                    <div class="quality">
                        <span>今天</span>
                        <span>{{ weather.air }}{{ weather.air_level }}</span>
                        <span>{{ weather.wea }}</span>
                    </div>
                </div>
                <!-- 明天 -->
                <div class="tomorrow">
                    <!-- 上面的温度 -->
                    <div class="temp">
                        <span>{{ tomorrowWea.tem2 }}~{{ tomorrowWea.tem1 }}°C</span>
                        <img :src="tomorrowImg" alt="">
                    </div>
                    <!-- 空气质量 -->
                    <div class="quality">
                        <span>明天</span>
                        <span>{{ tomorrowWea.air }}{{ tomorrowWea.air_level }}</span>
                        <span>{{ tomorrowWea.wea }}</span>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<style lang="scss" scoped>
.box {
    width: 74%;
    height: 40%;
    position: absolute;
    top: 100px;
    left: 50px;

    .content {
        background-color: rgba(255, 255, 255, .1);
        width: 100%;
        height: 80%;
        margin-top: 10px;

        .top {
            display: flex;
            justify-content: space-between;
            color: #bbb;
            align-items: center;
            // height: 46px;

            .left {
                margin-left: 10px;
                font-size: 20px;
                font-weight: bold;
            }

            .center {
                flex: 1;
                margin: 0 20px;

                .air {
                    background-color: #07a93c;
                    display: inline-block;
                    padding: 0 5px;
                    border-radius: 4px;
                    font-size: 10px;
                }

                .tem {
                    font-size: 14px;
                }
            }

            .right {
                font-size: 14px;
                margin-right: 10px;
            }
        }

        .tfs {
            color: #dbdbdb;
            font-size: 14px;
            padding: 0 10px;
            box-sizing: border-box;
            border: 1px solid #293c98;

            >div {
                display: flex;
                align-items: center;
                height: 40px;
                border-bottom: 2px solid #293c98;



                span:nth-child(2) {
                    flex: 1;
                }

            }
        }

        .tm {
            display: flex;
            justify-content: space-evenly;
            color: #dbdbdb;
            font-size: 14px;
            height: 60px;
            align-items: center;
            border: 1px solid #293c98;

            >div {
                width: 50%;
                padding: 0 10px;
                box-sizing: border-box;

                .temp {
                    display: flex;
                    justify-content: space-between;
                    width: 100%;

                    span {
                        flex: 1;
                    }
                }

                .quality {
                    display: flex;
                    justify-content: flex-start;
                    align-items: center;

                    span:nth-child(2) {
                        background-color: #07a93c;
                        border-radius: 2px;
                        display: inline;
                        margin-left: 4px;
                        font-size: 12px;
                    }

                    span:last-child {
                        flex: 1;
                        text-align: right;
                        margin-right: 4px;
                    }
                }
            }
        }
    }
}
</style>